package com.dk.common.dbaccess.entity;


import com.dk.common.dbaccess.listener.AuditingEntityListener;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.domain.Auditable;
import org.springframework.lang.Nullable;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import java.time.LocalDateTime;
import java.util.Optional;

/**
 * 公共 PO定义，包含记录的审计信息
 */
@Getter
@Setter
@MappedSuperclass
@ToString(callSuper = true)
@EntityListeners(AuditingEntityListener.class)
public abstract class AbstractAuditable extends AbstractPersistable
        implements Auditable<Long, Long, LocalDateTime> {


    /**
     * 创建者ID
     */
    @Nullable
    @Column(name = "created_by_user")
    private Long createdBy;

    /**
     * 创建者名称(创建时的值)
     */
    @Nullable
    @Column(name = "created_by_name", length = 128)
    private String createdByName;

    /**
     * 创建时间
     */
    @Nullable
    @Column(name = "created_date")
    private LocalDateTime createdDate;

    /**
     * 最后修改者ID
     */
    @Nullable
    @Column(name = "last_modified_by_user")
    private Long lastModifiedBy;

    /**
     * 最后修改者名称(修改时的值)
     */
    @Nullable
    @Column(name = "last_modified_by_name", length = 128)
    private String lastModifiedByName;

    /**
     * 最后修改时间
     */
    @Nullable
    @Column(name = "last_modified_date")
    private LocalDateTime lastModifiedDate;

    @Override
    public Optional<Long> getCreatedBy() {
        return Optional.ofNullable(createdBy);
    }

    @Override
    public Optional<LocalDateTime> getCreatedDate() {
        return Optional.ofNullable(createdDate);
    }

    @Override
    public Optional<Long> getLastModifiedBy() {
        return Optional.ofNullable(lastModifiedBy);
    }

    @Override
    public Optional<LocalDateTime> getLastModifiedDate() {
        return Optional.ofNullable(lastModifiedDate);
    }

}
